package org.jeecg.modules.qy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhyd.oauth.utils.UuidUtils;
import org.jeecg.modules.qy.entity.QyAccount;
import org.jeecg.modules.qy.entity.QyCompany;
import org.jeecg.modules.qy.mapper.QyCompanyMapper;
import org.jeecg.modules.qy.service.IQyAccountService;
import org.jeecg.modules.qy.service.IQyCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description: 公司信息表
 * @Author: jeecg-boot
 * @Date:   2021-03-05
 * @Version: V1.0
 */
@Service
public class QyCompanyServiceImpl extends ServiceImpl<QyCompanyMapper, QyCompany> implements IQyCompanyService {

    @Autowired
    private IQyAccountService accountService;

    @Override
    public void saveCompany(QyCompany qyCompany){
        qyCompany.setId(UuidUtils.getUUID());
        boolean b = super.save(qyCompany);
        if(b){
            //初始化公司权益数据
            QyAccount qa = new QyAccount();
            qa.setCompanyId(qyCompany.getId());
            qa.setCommoditySurplusNum(0);
            qa.setMuchCommoditySurplusNum(0);
            qa.setEffectTime(new Date());
            qa.setInvalidTime(new Date());
            qa.setMaxCodeNum(5000);
            accountService.save(qa);
        }

    }
}
